package homework4221;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Homework12 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("document/test.txt");
            byte[] buffer = new byte[1024];
            int len = -1;
            while((len = fis.read(buffer)) != -1){
                System.out.println("len+=" + len);
                String str = new String(buffer,0,len);
                System.out.println(str);
            }
            System.out.println("所有内容读取完毕");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException ex){
            ex.printStackTrace();
        }finally {
            if(fis != null){
                try {
                    fis.close();
                    fis = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
